<template>
  <div>
    我的论坛-><span>{{ channelSpan }}</span>
    主题名称<input type="text" v-model="paramsObj.title">
    作者<input type="text" v-model="paramsObj.name">
    起始日期<input type="text" v-model="paramsObj.startDate">
    结束日期<input type="text" v-model="paramsObj.endDate">
    <input type="button" value="搜索" @click="cutByItem(1)">
    <input type="button" value="发表话题" @click="addTheme()"><br>
    <table border="1" cellspacing="0" width="450">
      <thead>
      <tr>
        <th>主题</th>
        <th>作者</th>
        <th>回帖数量</th>
        <th>发帖时间</th>
      </tr>
      </thead>
      <tbody v-for="t in themeObj.records" :key="t.id">
      <tr>
        <td><a @click="setThemeId(t.id)">{{ t.title }}</a></td>
        <td>{{ t.user.name }}</td>
        <td>{{ t.replyNum }}</td>
        <td>{{ t.date }}</td>
      </tr>
      </tbody>
    </table>
    <div>
      <a v-for="n in themeObj.pages" :key="n"
         href="javascript:void(0)" @click="cutByItem(n)"
         style="margin-left: 10px">{{ n }}</a>
    </div>
  </div>
</template>

<script>
import axios from 'axios'

export default {
  data() {
    return {
      channelSpan: "",
      paramsObj: {},
      themeObj: {},
    }
  },
  created() {
    this.cutByItem(1);
  },
  methods: {
    cutByItem(pageNO) {
      axios.get("/project/theme/findById").then(resp => {
        var info = resp.data;
        this.channelSpan = info.name;
      })

      this.paramsObj.pageNO = pageNO;
      axios.get("/project/theme/cutByItem", {params: this.paramsObj}).then(resp => {
        this.themeObj = resp.data;
      })
    },
    addTheme() {
      this.$router.push({name: "AddTheme"});
    },
    setThemeId(themeId) {
      axios.get("/project/theme/setThemeId", {
        params: {
          themeId: themeId,
        }
      }).then(resp => {
        if (resp.data == "ok") {
          this.$router.push({name: "Reply"});
        }
      })
    },
  },
}

</script>

<style scoped>

</style>